package com.imooc.business.core;

import com.imooc.business.context.DataContext;
import com.imooc.business.core.executor.Process;
import com.imooc.module.collect.request.ParamsRequest;
import com.imooc.module.reponse.DataResponse;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author Tim
 * @Description:
 * @Version 1.0
 */
@Component
public class DefaultDataProcess implements DataProcess{

    @Setter(onMethod_ = @Autowired)
    private List<Process> processList;

    @Override
    public DataResponse process(ParamsRequest request) {
        //计算 | 查询
        DataContext context = new DataContext();
        context.setRequest(request);
        //策略模式应用
        processList.parallelStream().filter(process -> process.support(context)).
                forEach(process -> process.doProcess(context));
        return context.getResponse();
    }
}
